#include<iostream>
#include<algorithm>
using namespace std;

const int N = 310;

struct stu
{
    int chinese;
    int math;
    int english;
    int total;
    int id;
}arr[N];

bool cmp(struct stu s1,struct stu s2)
{
    if(s1.total !=s2.total)
    return s1.total > s2.total;
    else if (s1.total == s2.total)
    {
        if (s1.chinese < s2.chinese)
        {
            return s1.total < s2.total;
        }
        else if (s1.total > s2.total)
            return s1.total > s2.total;
    }
}

int main()
{
    int a;
    cin >> a;
    for (int i = 1; i <= a; i++)
    {
        cin >> arr[i].chinese >> arr[i].math >> arr[i].english;
        arr[i].total = arr[i].chinese + arr[i].math + arr[i].english;
        arr[i].id = i;
    }
    sort(arr+1, arr+a+1, cmp);
    for (int i = 1; i <= 5; i++)
    {
        cout << arr[i].id << " " << arr[i].total << endl;
    }

    return 0;
}
